home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -serious- / programming / other / tandem / teaching / 69.asm < prev    next >
Assembly Source File  |  1999-09-06  |  8KB  |  194 lines

  1. * 69.asm  Custom Requester     version 0.00     1.9.97
  2.  
  3.  
  4.  include 'Front.i'
  5.  
  6.  
  7. ; When tandem.library makes a requester, it will "attach" it to the
  8. ; currently popped window, i.e. it will use the following data in the
  9. ; currently popped window:
  10.  
  11. ;   xxp_ReqLeft    ;the requester xpos in the screen
  12. ;   xxp_ReqTop     ;the requester ypos in the screen
  13. ;   xxp_RFont      ;the font num
  14. ;   xxp_RFsty      ;the font style
  15. ;   xxp_RTspc      ;the text spacing
  16.  
  17. ; And when the requester is removed, the owning window will again be the
  18. ; currently popped window. Values are given to xxp_RFont,RFsty & RTspc from
  19. ; xxp_pref(a4) when a window is opened, but you may poke new values there
  20. ; to over-ride the preferences, before calling the requester.
  21.  
  22. ; But if there is no currently popped window, the requester is placed at
  23. ; screen position 0,0 and font num, style & tspace come from xxp_pref(a4).
  24.  
  25. ; The process is:
  26.  
  27. ;  1. create a workspace in the stack for setting up
  28. ;  2. call TLreqredi to do the initial setting up
  29. ;  3. TLreqredi puts default values in xxp_prfp(a4). These are pens &c
  30. ;     which your requester uses. You can over-ride these - in the program
  31. ;     below I insert the prefs for TLReqinfo-type requesters into xxp_prfp
  32. ;     which conveys the TLReqinfo user prefs to your custom requester.
  33. ;  4. xxp_prefp(a4) has the following things, which I recommend you use
  34. ;     in the drawing of your custom requester:
  35. ;     a. xxp_prfp+0  background pen
  36. ;     b. xxp_prfp+1  title pen (highlighted text)
  37. ;     c. xxp_prfp+2  text pen
  38. ;     d. xxp_prfp+3  horizontal gaps  } Used for "spreading out" your
  39. ;     e. xxp_prfp+4  vertical gaps    } requester
  40. ;  5. calculate the requester size. It if is too big, progressively do
  41. ;     the following:
  42. ;     a. poke 0 into xxp_RTspc
  43. ;     b. call TLnewfont #0,#0,#1 to attach Topaz/8
  44. ;     c. poke 0 into xxp_prfp+3
  45. ;     d. poke 0 into xxp_prfp+4
  46. ;     if it still won't fit, you have to re-design your requester. e.g. by
  47. ;     using TLTabs in it.
  48. ;  6. after width & height are calulated, call TLreqchek, which readies the
  49. ;     data in xxp_reqx,reqy,reqw,reqh. You can poke new values into
  50. ;     reqx & reqy after that to reposition the requester (but you must
  51. ;     make sure its bottom left will be on the screen).
  52. ;  7. your subroutine should then test xxp_ReqNull, and return if it is
  53. ;     null. (callers can set ReqNull to 0 to check the size & posn of the
  54. ;     requester).
  55. ;  8. Now, call TLreqon which actually turns the requester on. It will be
  56. ;     a blank window coloured in with the background pen in xxp_prfp.
  57. ;     (to over-ride that, poke a temporary value in xxp_prfp during TLreqon)
  58. ;  9. Now render the requester, using the above xxp_prfp data.
  59. ;     You may find TLbutprt,TLbuttxt,TLslider,TLtabs helpful in setting up
  60. ;     gadget-like areas on your requester. tandem.library rendering routines
  61. ;     TLreqarea,TLellipse,TLreqbev,TLgetilbm,TLpict may also be useful in
  62. ;     decorating the requester. TLreqedit has lots of options for font
  63. ;     display.
  64. ; 10. Attach help to your requester if applicable (using xxp_Help).
  65. ; 11. Your program may also do the following:
  66. ;     (a) poke a subroutine address into xxp_hook1(a4) which will be called
  67. ;         by TLreqon after it calculates the requester dimensions. You can
  68. ;         use that ot enlarge the requester for adding logos &c.
  69. ;     (b) poke a subroutine address into xxp_hook2(a4) which will be called
  70. ;         after your requester is drawn (after step 9 above).
  71. ;     If you do either of the above, you must at the beginning of your
  72. ;     requester program MOVEM.L D0-D7/A0-A6,-(A6) and then poke A7 to
  73. ;     xxp_Stak(a4), since hooks might want to know the register values
  74. ;     with which your requester program was called. Obviously, you will only
  75. ;     use hooks with "generic" type requesters which you plan to use in
  76. ;     many programs, like the requesters in tandem.library itself. Note
  77. ;     also that after TLreqon uses xxp_hook1 it puts 0 in it, to stop it
  78. ;     being accidentally left on, and your program should do the same after
  79. ;     testing xxp_hook2. Your program should pass A4 to the hooks, and
  80. ;     expect the hooks to trash all the registers (except A7 of course).
  81. ; 11. Call TLkeyboard for user response.
  82. ; 12. Process the user response. e.g.:
  83. ;     a. Call TLbutmon to see if buttons from TLbutprt have been clicked
  84. ;     b. Call TLslimon to see if slider(s) from TLslider have been clicked
  85. ;     c. Call TLtabmon to see if thumbtabs from TLtabs have been clicked
  86. ;     d. If an editable text area has been clicked, call TLReqedit
  87. ;     If the processing of the user input requires some redrawing of your
  88. ;     requester, go back to step 9. If not, go back to step 11. If the user
  89. ;     clicks a "Save" or "Cancel" button, or the "Esc" key, go to step 14.
  90. ;     TLmultiline may be useful for typing a series of strings into a
  91. ;     buffer.
  92. ; 13. Of course, while step 12 is taking place, your program will be putting
  93. ;     the effects of your users requests into its data sections, for
  94. ;     appropriate action when the requester closes. A sophisticated program
  95. ;     might even have another task acting on the data as the user
  96. ;     specifies it.
  97. ; 13. When the requester is ready to close, call TLreqoff.
  98. ; 14. It is probably best to call TLwslof, to remove clicks the user has
  99. ;     made off the requester window, after calling TLreqoff. tandem.library
  100. ;     requesters operate "synchronously", i.e. everything else in the
  101. ;     calling program stops until the requester is closed), which may not
  102. ;     be pleasing to the user, but in my opinion it is still worse to
  103. ;     have a delayed response to a click of another window some time later.
  104. ; 15. It is quite in order for requesters to do "power" things like loading
  105. ;     and running other programs, opening sub-windows & the like.
  106.  
  107.  
  108. width: dc.l 100  ; dummy width & height for the
  109. height: dc.l 50  ; requester below
  110.  
  111.  
  112. strings: dc.b 0
  113.  dc.b 'Error: out of memory',0 ;1
  114.  dc.b 'Click me!',0 ;2
  115.  ds.w 0
  116.  
  117.  
  118. * here is the "skeleton" of a custom requester.
  119. Program:
  120.  TLwindow #-1
  121.  beq Pr_bad
  122.  
  123.  bsr Custom
  124.  bra.s Pr_quit
  125.  
  126. Pr_bad:                     ;here if out of mem
  127.  TLbad #1
  128.  
  129. Pr_quit:
  130.  rts
  131.  
  132.  
  133. * make a custom requester (with nothing on it)
  134. Custom:
  135.  movem.l d0-d7/a0-a6,-(a7) ;save all
  136.  sub.w #xxp_WPort+4,a7     ;create dummy part xxp_wsuw
  137.  
  138.  move.l a7,a5              ;a5 points to dummy part xxp_wsuw
  139.  TLreqredi a5              ;set pop window, default values to xxp_prfp
  140.  beq .bad                  ;go if TLReqredi fails - unlikely
  141.  
  142.  move.l xxp_pref(a4),a0    ;prefs to prfp  } Optional:
  143.  move.l xxp_yinf(a0),xxp_prfp(a4)          } Use prefs for TLReqinfo-type
  144.  move.l xxp_yinf+4(a0),xxp_prfp+4(a4)      } requesters (but must set prfp)
  145.  
  146.  
  147.                            ;calculate requester size: set width,height
  148.                            ;(adjust prfp & font if necessary to make it fit)
  149.  
  150.  
  151.  TLreqchek width,height    ;check req size & position
  152.  beq .bad                  ;go if won't fit
  153.  
  154.  tst.w xxp_ReqNull(a4)     ;quit ok if ReqNull=0
  155.  beq .wrap
  156.  
  157.  TLreqon a5                ;open requester window
  158.  beq .bad                  ;go if can't
  159.  
  160.  move.b xxp_prfp+2(a4),xxp_FrontPen(a5)  ;} Set pens to TLReqinfo
  161.  move.b xxp_prfp(a4),xxp_BackPen(a5)     ;} prefernces (see above)
  162.  
  163.                            ;attach help
  164.  
  165. .draw:                     ;draw requester
  166.  
  167.  TLstring #2,#5,#6
  168.  
  169. .wait:                     ;wait for user response
  170.  TLwfront
  171.  TLkeyboard
  172.  
  173.  cmp.b #$80,d0             ;process user response, branching to
  174.  bne .wait                 ;  draw - if requester to be re-drawn
  175.                            ;  wait - if requester not to be re-drawn
  176.                            ;  clos - if user requested OK/Cancel &c
  177.  
  178.  
  179. .clos:
  180.  TLreqoff                  ;close requester window
  181.  moveq #-1,d0              ;signal ok
  182.  bra.s .wrap               ;return ok
  183.  
  184. .bad:
  185.  moveq #0,d0               ;too big/can't open window
  186.  
  187. .wrap:
  188.  move.w #-1,xxp_ReqNull(a4) ;leave ReqNull<>0
  189.  TLwslof
  190.  tst.l d0                  ;EQ if bad
  191.  add.w #xxp_WPort+4,a7
  192.  movem.l (a7)+,d0-d7/a0-a6
  193.  rts
  194.